<template>
	<view class="box-view">
		<navBar title="病害維修" goBackUrl="/pages/homePage/homePage" @goBack="navBack"></navBar>
		<view class="tabs">
			<view @click="changeTabsItem('repair-report')" :class="[active === 'repair-report' ? 'selected' : '']"
				class="tabs-item">維修計劃</view>
			<view @click="changeTabsItem('fill-record-repair')" :class="[active === 'fill-record-repair' ? 'selected' : '']"
				class="tabs-item">
				<view class="point">維修任務
					<u-badge  max="99" :value="badgeNum" :offset="[-5,45]" :absolute="true" style="z-index: 20;"></u-badge>
				</view>
			</view>
		</view>
		<repairReport ref="reportRef"  v-if="active==='repair-report'"></repairReport>
		<fill-record ref="recordRef"  v-if="active==='fill-record-repair'"></fill-record>
	</view>
</template>
<script>
	import repairReport from "./components/repair-report.vue";
	import fillRecord from "./components/fill-record.vue";
	import {hkRepairPlan_list } from "@/api/HongKong/hkAttendanceSheet.js";
	export default {
		name: "daily-metasomatic",
		components: {
			repairReport,
			fillRecord,
		},
		data() {
			return {
				// 当前激活的组件
				active: "repair-report",
				badgeNum:''
			}
		},
		 onShow() {
			console.debug('onShow')
			// if (this.$refs["component-child"]) {
			// 	if (this.active === 'fill-record-repair') {
			// 		console.log(2)
			// 		this.$refs["component-child"].paging.pageNum = 1;
			// 		this.$refs["component-child"].fillRecordArray = await this.$refs["component-child"].getFillRecordArray();
			// 	}
			// }
		},
		async mounted() {
			 this.badgeNum = await this.getBadgeNumber()
		},
		methods: {
			async getBackState(val) {
				this.badgeNum = await this.getBadgeNumber()
				console.log(this.$refs.recordRef, '=')
				this.$refs.recordRef.paging.pageNum = 1;
				this.$refs.recordRef.fillRecordArray = await this.$refs.recordRef.getFillRecordArray();
			},
			/** 切换tabs的页签 */
			async changeTabsItem(data) {
				// console.log(data)
				this.active = data;
				// console.log(this.$refs.recordRef, '=')
				if(data === 'fill-record-repair') {
					 this.badgeNum = await this.getBadgeNumber()
				}
			},
			getBadgeNumber(isFinish = false) {
				return new Promise(resolve => {
					hkRepairPlan_list({
						currPage: 1,
						pageSize:99999,
						params: {
							isFinish,
							repairDate:undefined,
							projectId: uni.getStorageSync("isOwner"),
							isDefaultQuery:true
						},
					}).then(async res => {
						const { list, total } = res.result;
						// this.badgeNum = 
						resolve(list.length || 0)
					});
				})

			},
			navBack(url) {
				uni.switchTab({
					url: url
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.box-view {
		/* #ifdef MP-WEIXIN */
		padding-top: 200rpx;
		/* #endif */
	}

	.required {
		&::before {
			content: "*";
			color: #ff6a6a;
		}
	}

	.tabs {
		line-height: 50upx;
		background: #fff;
		color: #445469;
		display: flex;
		align-items: center;
		justify-content: center;
		text-align: center;
		font-size: 36upx;
		font-weight: 500;
		border-top: 15px solid #f5f7fa;
		height: 55px;

		.tabs-item {
			border-bottom: 1px solid #e1e5ed;
			padding-bottom: 8upx;
			padding-top: 48upx;
			flex: 1;
			height: 100%;
			box-sizing: border-box;
		}

		.selected {
			color: #2f80ed;
			border-color: #2f80ed;
			font-weight: 800;
		}

		.point {
			position: relative;
		}
	}

	.container {
		box-sizing: border-box;
		background: #f5f7fa;
		font-size: 32upx;
	}
</style>